//
// Copyright (c) Microsoft Corporation.  All rights reserved.
//
//
// Use of this source code is subject to the terms of the Microsoft end-user
// license agreement (EULA) under which you licensed this SOFTWARE PRODUCT.
// If you did not accept the terms of the EULA, you are not authorized to use
// this source code. For a copy of the EULA, please see the LICENSE.RTF on your
// install media.
//
/*++

THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
PARTICULAR PURPOSE.

Module Name: 

        ist.hpp

Abstract:

       IST framework.

--*/


#pragma once
#include <cmthread.h>
#include <CRegEdit.h>

#include "xllp_udc.h"
#include "usbotg.h"
#include "xllp_usbotg.h"

class CIST : public CMiniThread {
public:
    CIST(LPCTSTR pszActiveKey,DWORD dwISTTimeout=INFINITE, DWORD dwTerminationTimeout=5000); // Take IST setting from registry.
    virtual ~CIST();
    virtual BOOL Init();
    virtual BOOL IntializeInterrupt(LPVOID pvData = NULL,  DWORD cbData = 0);
    HANDLE  GetIISRHandle() { return m_hIsrHandler; };
    DWORD   GetIRQ() { return m_dwIrq; };
    DWORD   GetSysIntr() { return m_dwSysIntr; };
    BOOL    IsIISRLoaded() { return m_hIsrHandler!=NULL; };
    HANDLE  GetISTEvent() { return m_hISTEvent; };
    BOOL    IntChainHandlerIoControl(DWORD dwIoContro, PVOID pInPtr, DWORD dwInSize, PVOID pOutPtr, DWORD dwOutSize,PDWORD pdwActualWrite) ;
protected:
    DWORD   m_ISTTimeout;
    DWORD   m_TerminationTimeout;
private:    
    virtual DWORD   ThreadRun();
    virtual BOOL    ISTProcess() = 0 ;
    virtual BOOL    ISTTimeout() { return TRUE; };
    CRegistryEdit   m_Reg;
    
    BOOL            m_fAllocatedSysIntr;
    HANDLE          m_hIsrHandler;
    HANDLE          m_hISTEvent;
    DWORD           m_dwIrq;
    DWORD           m_dwSysIntr;
    BOOL            m_fIntInitialized;
};


